package keke;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class Mainboke120202 {
	public static void main(String[] args)  {
		String FILENAME = "test.txt";
		
		//write using PrintWriter
		/*
		PrintWriter pw=null;
		try {
			pw = new PrintWriter(FILENAME);
			for(int i = 0;i<10000000;i++){
			pw.println(1);
		}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}finally{
			pw.close();
		}
		System.out.println("write  using PrintWriter done");
		*/
		BufferedWriter bw=null;
		try {
			bw=new BufferedWriter(new FileWriter(FILENAME));
			for(int i = 0;i<10000000;i++){ 
		            bw.write(1);  
		            bw.newLine();  
			}
		} catch (IOException e1) {
			e1.printStackTrace();
		}finally{
			try {
				bw.flush();
				bw.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		System.out.println("write  using BufferedWriter done");
		//read using Scanner
		/*
		Scanner scanner=null;
		try {
			scanner = new Scanner(new File(FILENAME));
			while(scanner.hasNextLine()){
				scanner.nextLine();
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}finally{
			scanner.close();
		}
		System.out.println("read using Scanner done");
		*/
		//read using BufferedReader
		BufferedReader br = null;
		try {
			 br = new BufferedReader(new FileReader(new File(FILENAME)));
			 while(br.readLine()!=null){};
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		System.out.println("read using BufferedReader done");
	}
}

